<!--
 * @Author: 码上talk|RC
 * @Date: 2021-01-05 14:57:14
 * @LastEditTime: 2021-01-05 15:22:24
 * @LastEditors: 码上talk|RC
 * @Description: 
 * @FilePath: /tacomall-merchant/src/components/img-video-previewer/popup.vue
 * @微信:  13680065830
 * @邮箱:  3189482282@qq.com
 * @oops: Just do what I think it is right
-->

<template>
    <transition name="popup-fade">
        <div class="previewer-popup" @click="visible = false" v-if="visible">
            <div class="p-box" @click.stop>
                <div class="b-img" :style="{width: width + 'px', height: height + 'px'}">
                    <img :src="src" alt />
                </div>
            </div>
        </div>
    </transition>
</template>

<script>
const FIXED_WIDTH = 500
export default {
    data() {
        return {
            visible: false,
            src: null,
            width: FIXED_WIDTH,
            height: 0
        }
    },
    watch: {
        'src': function (val) {
            const img = new Image()
            img.src = val
            img.onload = () => {
                this.height = FIXED_WIDTH / img.width * img.height
            }
        }
    }
}
</script>


<style lang="less">
.previewer-popup {
    position: fixed;
    top: 0;
    bottom: 0;
    width: 100%;
    background: rgba(0, 0, 0, 0.7);
    z-index: 999;
    .p-box {
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        display: flex;
        flex-direction: column;
        align-items: center;
        .b-img {
            position: relative;
            img {
                position: absolute;
                top: 50%;
                left: 50%;
                transform: translate(-50%, -50%);
                width: 100%;
                height: 100%;
            }
        }
    }
}

.popup-fade-enter-active,
.popup-fade-leave-active {
    transition: opacity 0.4s;
}

.popup-fade-enter,
.popup-fade-leave-to {
    opacity: 0;
}
</style>